-- special_shield
-- created by dengc
-- 带特殊能量值的特殊护盾

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 记录
    record = function(target, prop, path)
        -- 不是冰霜泰坦
        if target.classId ~= 510 then
            return false;
        end

        -- 初始赋予时，修正下护盾能量
        local value;
        local combineProp;
        if path == "skill" then
            -- 需要和楼层挂钩
            local floor = DungeonM.currentLayer();
            value = math.max(8 * floor - 140, 100);

            -- 保底值为基础值
            combineProp = prop;
            value = iif(combineProp[3] > value, combineProp[3], value);

            PropM.record(target, {combineProp[1], combineProp[2], value - combineProp[3], -1}, "special_shield");

            if not target.dbase:query("is_shield_init") then
                -- 设置一下当前的能量
                target.dbase:set("energy", value);

                -- 设置下最大能量
                target.dbase:set("max_energy", value);

                -- 标记已记录
                target.dbase:set("is_shield_init", true);
            end

            -- 标记需要护盾
            ME.user.dbase:setTemp("ice_titant_shield", 1);
        else
            -- 能量减少
            local reduceValue = prop[3];
            if reduceValue >= 0 then
                return;
            end

            local shieldId = "default";

            -- 记录下当前的能量
            value = math.max(0, target.dbase:query("energy") + reduceValue);
            target.dbase:set("energy", value);

            -- 抛出事件
            EventMgr.fire(event.COLLECT_ENERGY, {
                ["amount"] = reduceValue,
                ["pos"] = target:getPos(),
                ["attrib"] = "energy",
                ["need_effect"] = false,
            });

            combineProp = PropM.combine(target, "special_shield", OBJECT_TYPE_AVALON_CANNON);
            local dif = combineProp[3] + reduceValue;

            -- 检查护盾能量，没有能量了，清除护盾属性
            if dif <= 0 then
                combineProp = PropM.combine(target, "resist", "attack");
                if combineProp[3] > 0 then
                    PropM.record(target, {combineProp[1], combineProp[2], -combineProp[3], -1}, "mixed");
                end

                combineProp = PropM.combine(target, "resist", "magic");
                if combineProp[3] > 0 then
                    PropM.record(target, {combineProp[1], combineProp[2], -combineProp[3], -1}, "mixed");
                end

                shieldId = "shield_broken";
            end

            -- 抛出受到debuf影响事件
            EventMgr.fire(event.BOSS_RECIEVE_DEBUF, { ["skillId"] = shieldId, ["pos"] = DungeonBossM.getBossPos(), });
        end

        return false;
    end,
};
